Skip to content

ENH: add nunique delegation#861

Merged
lucascolley merged 2 commits into
data-apis:mainfrom
floze-the-genius:feat/nunique-delegation
Jul 23, 2026
Merged

ENH: add nunique delegation#861
lucascolley merged 2 commits into
data-apis:mainfrom
floze-the-genius:feat/nunique-delegation

Conversation

@floze-the-genius

Copy link
Copy Markdown
Contributor

Completes the remaining nunique item in #100.

Summary

  • move the public nunique wrapper and backend dispatch into _delegation.py
  • delegate eager NumPy and CuPy arrays to native unique(..., equal_nan=False)
  • delegate eager PyTorch arrays to native unique, while retaining the generic fallback for devices such as meta that do not support data-dependent shapes
  • preserve the JAX static-size implementation and the lazy/array-agnostic fallback for Dask, strict, sparse, and wrapped namespaces
  • add a backend dispatch test that fails if supported native namespaces reach the generic implementation

The equal_nan=False argument preserves the existing Array API behavior where separate NaNs count as separate unique values.

Validation

  • pytest -q -p no:cacheprovider: 4347 passed, 8984 skipped, 18 xfailed, 2 xpassed
  • pytest -q -p no:cacheprovider tests/test_funcs.py::TestNUnique: 38 passed, 72 skipped in the lean environment
  • expanded focused backend run before slimming the environment: 75 passed, 34 skipped, 1 expected Dask xfail (NumPy, array-api-strict, Dask, sparse, PyTorch CPU/meta, and JAX CPU available)
  • ruff check on changed files
  • ruff format --check on changed files
  • numpydoc lint on changed implementation modules
  • validate-pyproject pyproject.toml
  • public export consistency test

CuPy could not be installed on this macOS host; its current native unique signature was checked to support equal_nan and CI covers the backend matrix.

@lucascolley lucascolley added enhancement New feature or request delegation labels Jul 20, 2026
@lucascolley
lucascolley self-requested a review July 20, 2026 15:06
Comment thread src/array_api_extra/_delegation.py Outdated
@lucascolley lucascolley added this to the 0.11.1 milestone Jul 23, 2026

@lucascolley lucascolley left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

happy if CI is happy!

@lucascolley
lucascolley merged commit 681ae8b into data-apis:main Jul 23, 2026
13 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

delegation enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants